function getQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}
layui.use('table', function(){
    var table = layui.table;
    var delurl = "/general/erp5/public/tripapi/travel/Delete";
    //方法级渲染
    table.render({
        elem: '#apply_list'
        ,url: '/general/erp5/public/tripapi/travel/GetOtherListByAjax?nid='+getQueryString('nids')
        ,response: {
            statusName: 'status'
            ,statusCode: 200
            ,msgName: 'msg'
            ,countName: 'count'
            ,dataName: 'data'
        }
        ,cols: [[
            {checkbox: true, fixed: true}
            ,{field:'id', title: 'ID', width: 150, align:'center'}
            ,{field:'contract_name', title: '项目合同名称', width: 150, align:'center'}
            ,{field:'apply_num', title: '出差申请单号',width: 150, align:'center'}
            ,{field:'status', title: '审核状态',width: 150, align:'center'}
            ,{field:'write_time', title: '填写日期', width: 150, align:'center'}
            ,{field:'contract_num', title: '合同编号', width: 150,hide:true, align:'center'}
            ,{field:'traveler', title: '出差人员名单', width: 150, align:'center'}
            ,{field:'apply_user', title: '申请人', width: 150, align:'center'}
            ,{field:'charge_user', title: '负责人', width: 150, align:'center'}
            ,{field:'travel_time', title: '出差时间', width: 150, align:'center'}
            ,{field:'travel_place', title: '出差地点',width: 150, align:'center'}
            ,{field:'reason', title: '出差事由',width: 150,hide:true, align:'center'}
            ,{field:'contacter', title: '接洽人',width: 150,hide:true, align:'center'}
            ,{field:'business_money', title: '业务预算小计',width: 150, align:'center'}
            ,{field:'budget_money', title: '费用预算合计',width: 150, align:'center'}
            ,{field:'creator', title: '创建人',width: 150, align:'center'}
            ,{field:'create_time', title: '创建时间',width: 150, align:'center'}
            ,{field:'', title: '操作', toolbar:'#tab1Bar',width: 150, align:'center'}
        ]]
        ,id: 'testReload'
        ,page: true
        ,toolbar:"#tab2Bar"
        ,text: { none: '暂无相关数据' }
    });
    table.on('tool(user)', function (obj) {
        switch(obj.event){
            case 'show':
                location.replace("/general/erp5/public/tripapi/travel/show?id=" + obj.data.id);
                break;
        }

    })
    var $ = layui.$, active = {
        reload: function(){
            var demoReload = $('#idreload');
            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    key: {
                        id: demoReload.val()
                    }
                }
            }, 'data');
        }
    };

    $('.apply_table .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
});